package kafka

import (
	"fmt"
	"github.com/Shopify/sarama"
	"time"
)

func Produce(addr, tp, msg string) {
	producer, err := sarama.NewAsyncProducer([]string{addr}, nil)
	if err != nil {
		panic(err)
	}
	defer producer.Close()
	go func() {
		for e := range producer.Errors() {
			fmt.Println(e)
		}
	}()
	for range time.Tick(2 * time.Second) {
		ms := &sarama.ProducerMessage{}
		ms.Topic = tp
		ms.Value = sarama.StringEncoder(msg)
		producer.Input() <- ms
	}
}
